<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"> <style>
	.KEYW {color: #933;}
	.COMM {color: #bbb; font-style: italic;}
	.NUMB {color: #393;}
	.STRN {color: #393;}
	.REGX {color: #339;}
	.line {border-right: 1px dotted #666; color: #666; font-style: normal;}
	</style></head><body><pre><span class='line'>  1</span> <span class="COMM">/* base64x-1.1.14 (c) 2012-2018 Kenji Urushima | kjur.github.com/jsrsasign/license
<span class='line'>  2</span>  */</span><span class="WHIT">
<span class='line'>  3</span> </span><span class="COMM">/*
<span class='line'>  4</span>  * base64x.js - Base64url and supplementary functions for Tom Wu's base64.js library
<span class='line'>  5</span>  *
<span class='line'>  6</span>  * version: 1.1.14 (2018-Apr-21)
<span class='line'>  7</span>  *
<span class='line'>  8</span>  * Copyright (c) 2012-2018 Kenji Urushima (kenji.urushima@gmail.com)
<span class='line'>  9</span>  *
<span class='line'> 10</span>  * This software is licensed under the terms of the MIT License.
<span class='line'> 11</span>  * https://kjur.github.io/jsrsasign/license
<span class='line'> 12</span>  *
<span class='line'> 13</span>  * The above copyright and license notice shall be 
<span class='line'> 14</span>  * included in all copies or substantial portions of the Software.
<span class='line'> 15</span>  */</span><span class="WHIT">
<span class='line'> 16</span> 
<span class='line'> 17</span> </span><span class="COMM">/**
<span class='line'> 18</span>  * @fileOverview
<span class='line'> 19</span>  * @name base64x-1.1.js
<span class='line'> 20</span>  * @author Kenji Urushima kenji.urushima@gmail.com
<span class='line'> 21</span>  * @version jsrsasign 8.0.12 base64x 1.1.14 (2018-Apr-22)
<span class='line'> 22</span>  * @since jsrsasign 2.1
<span class='line'> 23</span>  * @license &lt;a href="https://kjur.github.io/jsrsasign/license/">MIT License&lt;/a>
<span class='line'> 24</span>  */</span><span class="WHIT">
<span class='line'> 25</span> 
<span class='line'> 26</span> </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">KJUR</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 27</span> </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">typeof</span><span class="WHIT"> </span><span class="NAME">KJUR</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="STRN">"undefined"</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="PUNC">!</span><span class="NAME">KJUR</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="NAME">KJUR</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 28</span> </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">typeof</span><span class="WHIT"> </span><span class="NAME">KJUR.lang</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="STRN">"undefined"</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="PUNC">!</span><span class="NAME">KJUR.lang</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="NAME">KJUR.lang</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 29</span> 
<span class='line'> 30</span> </span><span class="COMM">/**
<span class='line'> 31</span>  * String and its utility class &lt;br/>
<span class='line'> 32</span>  * This class provides some static utility methods for string.
<span class='line'> 33</span>  * @class String and its utility class
<span class='line'> 34</span>  * @author Kenji Urushima
<span class='line'> 35</span>  * @version 1.0 (2016-Aug-05)
<span class='line'> 36</span>  * @since base64x 1.1.7 jsrsasign 5.0.13
<span class='line'> 37</span>  * @description
<span class='line'> 38</span>  * &lt;br/>
<span class='line'> 39</span>  * This class provides static methods for string utility.
<span class='line'> 40</span>  * &lt;dl>
<span class='line'> 41</span>  * &lt;dt>&lt;b>STRING TYPE CHECKERS&lt;/b>
<span class='line'> 42</span>  * &lt;dd>
<span class='line'> 43</span>  * &lt;ul>
<span class='line'> 44</span>  * &lt;li>{@link KJUR.lang.String.isInteger} - check whether argument is an integer&lt;/li>
<span class='line'> 45</span>  * &lt;li>{@link KJUR.lang.String.isHex} - check whether argument is a hexadecimal string&lt;/li>
<span class='line'> 46</span>  * &lt;li>{@link KJUR.lang.String.isBase64} - check whether argument is a Base64 encoded string&lt;/li>
<span class='line'> 47</span>  * &lt;li>{@link KJUR.lang.String.isBase64URL} - check whether argument is a Base64URL encoded string&lt;/li>
<span class='line'> 48</span>  * &lt;li>{@link KJUR.lang.String.isIntegerArray} - check whether argument is an array of integers&lt;/li>
<span class='line'> 49</span>  * &lt;/ul>
<span class='line'> 50</span>  * &lt;/dl>
<span class='line'> 51</span>  */</span><span class="WHIT">
<span class='line'> 52</span> </span><span class="NAME">KJUR.lang.String</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 53</span> 
<span class='line'> 54</span> </span><span class="COMM">/**
<span class='line'> 55</span>  * Base64URL and supplementary functions for Tom Wu's base64.js library.&lt;br/>
<span class='line'> 56</span>  * This class is just provide information about global functions
<span class='line'> 57</span>  * defined in 'base64x.js'. The 'base64x.js' script file provides
<span class='line'> 58</span>  * global functions for converting following data each other.
<span class='line'> 59</span>  * &lt;ul>
<span class='line'> 60</span>  * &lt;li>(ASCII) String&lt;/li>
<span class='line'> 61</span>  * &lt;li>UTF8 String including CJK, Latin and other characters&lt;/li>
<span class='line'> 62</span>  * &lt;li>byte array&lt;/li>
<span class='line'> 63</span>  * &lt;li>hexadecimal encoded String&lt;/li>
<span class='line'> 64</span>  * &lt;li>Full URIComponent encoded String (such like "%69%94")&lt;/li>
<span class='line'> 65</span>  * &lt;li>Base64 encoded String&lt;/li>
<span class='line'> 66</span>  * &lt;li>Base64URL encoded String&lt;/li>
<span class='line'> 67</span>  * &lt;/ul>
<span class='line'> 68</span>  * All functions in 'base64x.js' are defined in {@link global__} and not
<span class='line'> 69</span>  * in this class.
<span class='line'> 70</span>  * 
<span class='line'> 71</span>  * @class Base64URL and supplementary functions for Tom Wu's base64.js library
<span class='line'> 72</span>  * @author Kenji Urushima
<span class='line'> 73</span>  * @version 1.1 (07 May 2012)
<span class='line'> 74</span>  * @requires base64.js
<span class='line'> 75</span>  * @see &lt;a href="https://kjur.github.io/jsjws/">'jwjws'(JWS JavaScript Library) home page https://kjur.github.io/jsjws/&lt;/a>
<span class='line'> 76</span>  * @see &lt;a href="https://kjur.github.io/jsrsasigns/">'jwrsasign'(RSA Sign JavaScript Library) home page https://kjur.github.io/jsrsasign/&lt;/a>
<span class='line'> 77</span>  */</span><span class="WHIT">
<span class='line'> 78</span> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">Base64x</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 79</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 80</span> 
<span class='line'> 81</span> </span><span class="COMM">// ==== string / byte array ================================</span><span class="WHIT">
<span class='line'> 82</span> </span><span class="COMM">/**
<span class='line'> 83</span>  * convert a string to an array of character codes
<span class='line'> 84</span>  * @name stoBA
<span class='line'> 85</span>  * @function
<span class='line'> 86</span>  * @param {String} s
<span class='line'> 87</span>  * @return {Array of Numbers} 
<span class='line'> 88</span>  */</span><span class="WHIT">
<span class='line'> 89</span> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">stoBA</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 90</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">a</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">Array</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 91</span> </span><span class="WHIT">    </span><span class="KEYW">for</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NAME">s.length</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="PUNC">++</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 92</span> </span><span class="WHIT">	</span><span class="NAME">a</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">s.charCodeAt</span><span class="PUNC">(</span><span class="NAME">i</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 93</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 94</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">a</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 95</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 96</span> 
<span class='line'> 97</span> </span><span class="COMM">/**
<span class='line'> 98</span>  * convert an array of character codes to a string
<span class='line'> 99</span>  * @name BAtos
<span class='line'>100</span>  * @function
<span class='line'>101</span>  * @param {Array of Numbers} a array of character codes
<span class='line'>102</span>  * @return {String} s
<span class='line'>103</span>  */</span><span class="WHIT">
<span class='line'>104</span> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">BAtos</span><span class="PUNC">(</span><span class="NAME">a</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>105</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">s</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">""</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>106</span> </span><span class="WHIT">    </span><span class="KEYW">for</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NAME">a.length</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="PUNC">++</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>107</span> </span><span class="WHIT">	</span><span class="NAME">s</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">s</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">String.fromCharCode</span><span class="PUNC">(</span><span class="NAME">a</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>108</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>109</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">s</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>110</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>111</span> 
<span class='line'>112</span> </span><span class="COMM">// ==== byte array / hex ================================</span><span class="WHIT">
<span class='line'>113</span> </span><span class="COMM">/**
<span class='line'>114</span>  * convert an array of bytes(Number) to hexadecimal string.&lt;br/>
<span class='line'>115</span>  * @name BAtohex
<span class='line'>116</span>  * @function
<span class='line'>117</span>  * @param {Array of Numbers} a array of bytes
<span class='line'>118</span>  * @return {String} hexadecimal string
<span class='line'>119</span>  */</span><span class="WHIT">
<span class='line'>120</span> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">BAtohex</span><span class="PUNC">(</span><span class="NAME">a</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>121</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">s</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">""</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>122</span> </span><span class="WHIT">    </span><span class="KEYW">for</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NAME">a.length</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="PUNC">++</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>123</span> </span><span class="WHIT">	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">hex1</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">a</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">.</span><span class="NAME">toString</span><span class="PUNC">(</span><span class="NUMB">16</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>124</span> </span><span class="WHIT">	</span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">hex1.length</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="NUMB">1</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="NAME">hex1</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">"0"</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">hex1</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>125</span> </span><span class="WHIT">	</span><span class="NAME">s</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">s</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">hex1</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>126</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>127</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">s</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>128</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>129</span> 
<span class='line'>130</span> </span><span class="COMM">// ==== string / hex ================================</span><span class="WHIT">
<span class='line'>131</span> </span><span class="COMM">/**
<span class='line'>132</span>  * convert a ASCII string to a hexadecimal string of ASCII codes.&lt;br/>
<span class='line'>133</span>  * NOTE: This can't be used for non ASCII characters.
<span class='line'>134</span>  * @name stohex
<span class='line'>135</span>  * @function
<span class='line'>136</span>  * @param {s} s ASCII string
<span class='line'>137</span>  * @return {String} hexadecimal string
<span class='line'>138</span>  */</span><span class="WHIT">
<span class='line'>139</span> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">stohex</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>140</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">BAtohex</span><span class="PUNC">(</span><span class="NAME">stoBA</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>141</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>142</span> 
<span class='line'>143</span> </span><span class="COMM">// ==== string / base64 ================================</span><span class="WHIT">
<span class='line'>144</span> </span><span class="COMM">/**
<span class='line'>145</span>  * convert a ASCII string to a Base64 encoded string.&lt;br/>
<span class='line'>146</span>  * NOTE: This can't be used for non ASCII characters.
<span class='line'>147</span>  * @name stob64
<span class='line'>148</span>  * @function
<span class='line'>149</span>  * @param {s} s ASCII string
<span class='line'>150</span>  * @return {String} Base64 encoded string
<span class='line'>151</span>  */</span><span class="WHIT">
<span class='line'>152</span> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">stob64</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>153</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">hex2b64</span><span class="PUNC">(</span><span class="NAME">stohex</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>154</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>155</span> 
<span class='line'>156</span> </span><span class="COMM">// ==== string / base64url ================================</span><span class="WHIT">
<span class='line'>157</span> </span><span class="COMM">/**
<span class='line'>158</span>  * convert a ASCII string to a Base64URL encoded string.&lt;br/>
<span class='line'>159</span>  * NOTE: This can't be used for non ASCII characters.
<span class='line'>160</span>  * @name stob64u
<span class='line'>161</span>  * @function
<span class='line'>162</span>  * @param {s} s ASCII string
<span class='line'>163</span>  * @return {String} Base64URL encoded string
<span class='line'>164</span>  */</span><span class="WHIT">
<span class='line'>165</span> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">stob64u</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>166</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">b64tob64u</span><span class="PUNC">(</span><span class="NAME">hex2b64</span><span class="PUNC">(</span><span class="NAME">stohex</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>167</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>168</span> 
<span class='line'>169</span> </span><span class="COMM">/**
<span class='line'>170</span>  * convert a Base64URL encoded string to a ASCII string.&lt;br/>
<span class='line'>171</span>  * NOTE: This can't be used for Base64URL encoded non ASCII characters.
<span class='line'>172</span>  * @name b64utos
<span class='line'>173</span>  * @function
<span class='line'>174</span>  * @param {s} s Base64URL encoded string
<span class='line'>175</span>  * @return {String} ASCII string
<span class='line'>176</span>  */</span><span class="WHIT">
<span class='line'>177</span> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">b64utos</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>178</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">BAtos</span><span class="PUNC">(</span><span class="NAME">b64toBA</span><span class="PUNC">(</span><span class="NAME">b64utob64</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>179</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>180</span> 
<span class='line'>181</span> </span><span class="COMM">// ==== base64 / base64url ================================</span><span class="WHIT">
<span class='line'>182</span> </span><span class="COMM">/**
<span class='line'>183</span>  * convert a Base64 encoded string to a Base64URL encoded string.&lt;br/>
<span class='line'>184</span>  * @name b64tob64u
<span class='line'>185</span>  * @function
<span class='line'>186</span>  * @param {String} s Base64 encoded string
<span class='line'>187</span>  * @return {String} Base64URL encoded string
<span class='line'>188</span>  * @example
<span class='line'>189</span>  * b64tob64u("ab+c3f/==") &rarr; "ab-c3f_"
<span class='line'>190</span>  */</span><span class="WHIT">
<span class='line'>191</span> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">b64tob64u</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>192</span> </span><span class="WHIT">    </span><span class="NAME">s</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">s.replace</span><span class="PUNC">(</span><span class="REGX">/\=/g</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">""</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>193</span> </span><span class="WHIT">    </span><span class="NAME">s</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">s.replace</span><span class="PUNC">(</span><span class="REGX">/\+/g</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"-"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>194</span> </span><span class="WHIT">    </span><span class="NAME">s</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">s.replace</span><span class="PUNC">(</span><span class="REGX">/\//g</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"_"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>195</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">s</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>196</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>197</span> 
<span class='line'>198</span> </span><span class="COMM">/**
<span class='line'>199</span>  * convert a Base64URL encoded string to a Base64 encoded string.&lt;br/>
<span class='line'>200</span>  * @name b64utob64
<span class='line'>201</span>  * @function
<span class='line'>202</span>  * @param {String} s Base64URL encoded string
<span class='line'>203</span>  * @return {String} Base64 encoded string
<span class='line'>204</span>  * @example
<span class='line'>205</span>  * b64utob64("ab-c3f_") &rarr; "ab+c3f/=="
<span class='line'>206</span>  */</span><span class="WHIT">
<span class='line'>207</span> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">b64utob64</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>208</span> </span><span class="WHIT">    </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">s.length</span><span class="WHIT"> </span><span class="PUNC">%</span><span class="WHIT"> </span><span class="NUMB">4</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="NAME">s</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">s</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="STRN">"=="</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>209</span> </span><span class="WHIT">    </span><span class="KEYW">else</span><span class="WHIT"> </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">s.length</span><span class="WHIT"> </span><span class="PUNC">%</span><span class="WHIT"> </span><span class="NUMB">4</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="NUMB">3</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="NAME">s</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">s</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="STRN">"="</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>210</span> </span><span class="WHIT">    </span><span class="NAME">s</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">s.replace</span><span class="PUNC">(</span><span class="REGX">/-/g</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"+"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>211</span> </span><span class="WHIT">    </span><span class="NAME">s</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">s.replace</span><span class="PUNC">(</span><span class="REGX">/_/g</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"/"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>212</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">s</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>213</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>214</span> 
<span class='line'>215</span> </span><span class="COMM">// ==== hex / base64url ================================</span><span class="WHIT">
<span class='line'>216</span> </span><span class="COMM">/**
<span class='line'>217</span>  * convert a hexadecimal string to a Base64URL encoded string.&lt;br/>
<span class='line'>218</span>  * @name hextob64u
<span class='line'>219</span>  * @function
<span class='line'>220</span>  * @param {String} s hexadecimal string
<span class='line'>221</span>  * @return {String} Base64URL encoded string
<span class='line'>222</span>  * @description
<span class='line'>223</span>  * convert a hexadecimal string to a Base64URL encoded string.
<span class='line'>224</span>  * NOTE: If leading "0" is omitted and odd number length for
<span class='line'>225</span>  * hexadecimal leading "0" is automatically added.
<span class='line'>226</span>  */</span><span class="WHIT">
<span class='line'>227</span> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">hextob64u</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>228</span> </span><span class="WHIT">    </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">s.length</span><span class="WHIT"> </span><span class="PUNC">%</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="NUMB">1</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="NAME">s</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">"0"</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">s</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>229</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">b64tob64u</span><span class="PUNC">(</span><span class="NAME">hex2b64</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>230</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>231</span> 
<span class='line'>232</span> </span><span class="COMM">/**
<span class='line'>233</span>  * convert a Base64URL encoded string to a hexadecimal string.&lt;br/>
<span class='line'>234</span>  * @name b64utohex
<span class='line'>235</span>  * @function
<span class='line'>236</span>  * @param {String} s Base64URL encoded string
<span class='line'>237</span>  * @return {String} hexadecimal string
<span class='line'>238</span>  */</span><span class="WHIT">
<span class='line'>239</span> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">b64utohex</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>240</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">b64tohex</span><span class="PUNC">(</span><span class="NAME">b64utob64</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>241</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>242</span> 
<span class='line'>243</span> </span><span class="COMM">// ==== utf8 / base64url ================================</span><span class="WHIT">
<span class='line'>244</span> 
<span class='line'>245</span> </span><span class="COMM">/**
<span class='line'>246</span>  * convert a UTF-8 encoded string including CJK or Latin to a Base64URL encoded string.&lt;br/>
<span class='line'>247</span>  * @name utf8tob64u
<span class='line'>248</span>  * @function
<span class='line'>249</span>  * @param {String} s UTF-8 encoded string
<span class='line'>250</span>  * @return {String} Base64URL encoded string
<span class='line'>251</span>  * @since 1.1
<span class='line'>252</span>  */</span><span class="WHIT">
<span class='line'>253</span> 
<span class='line'>254</span> </span><span class="COMM">/**
<span class='line'>255</span>  * convert a Base64URL encoded string to a UTF-8 encoded string including CJK or Latin.&lt;br/>
<span class='line'>256</span>  * @name b64utoutf8
<span class='line'>257</span>  * @function
<span class='line'>258</span>  * @param {String} s Base64URL encoded string
<span class='line'>259</span>  * @return {String} UTF-8 encoded string
<span class='line'>260</span>  * @since 1.1
<span class='line'>261</span>  */</span><span class="WHIT">
<span class='line'>262</span> 
<span class='line'>263</span> </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">utf8tob64u</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">b64utoutf8</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>264</span> 
<span class='line'>265</span> </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">typeof</span><span class="WHIT"> </span><span class="NAME">Buffer</span><span class="WHIT"> </span><span class="PUNC">===</span><span class="WHIT"> </span><span class="STRN">'function'</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>266</span> </span><span class="WHIT">  </span><span class="NAME">utf8tob64u</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>267</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">b64tob64u</span><span class="PUNC">(</span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">Buffer</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">'utf8'</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">toString</span><span class="PUNC">(</span><span class="STRN">'base64'</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>268</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>269</span> 
<span class='line'>270</span> </span><span class="WHIT">  </span><span class="NAME">b64utoutf8</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>271</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">Buffer</span><span class="PUNC">(</span><span class="NAME">b64utob64</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">'base64'</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">toString</span><span class="PUNC">(</span><span class="STRN">'utf8'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>272</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>273</span> </span><span class="PUNC">}</span><span class="WHIT"> </span><span class="KEYW">else</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>274</span> </span><span class="WHIT">  </span><span class="NAME">utf8tob64u</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>275</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">hextob64u</span><span class="PUNC">(</span><span class="NAME">uricmptohex</span><span class="PUNC">(</span><span class="NAME">encodeURIComponentAll</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>276</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>277</span> 
<span class='line'>278</span> </span><span class="WHIT">  </span><span class="NAME">b64utoutf8</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>279</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">decodeURIComponent</span><span class="PUNC">(</span><span class="NAME">hextouricmp</span><span class="PUNC">(</span><span class="NAME">b64utohex</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>280</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>281</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>282</span> 
<span class='line'>283</span> </span><span class="COMM">// ==== utf8 / base64url ================================</span><span class="WHIT">
<span class='line'>284</span> </span><span class="COMM">/**
<span class='line'>285</span>  * convert a UTF-8 encoded string including CJK or Latin to a Base64 encoded string.&lt;br/>
<span class='line'>286</span>  * @name utf8tob64
<span class='line'>287</span>  * @function
<span class='line'>288</span>  * @param {String} s UTF-8 encoded string
<span class='line'>289</span>  * @return {String} Base64 encoded string
<span class='line'>290</span>  * @since 1.1.1
<span class='line'>291</span>  */</span><span class="WHIT">
<span class='line'>292</span> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">utf8tob64</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>293</span> </span><span class="WHIT">  </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">hex2b64</span><span class="PUNC">(</span><span class="NAME">uricmptohex</span><span class="PUNC">(</span><span class="NAME">encodeURIComponentAll</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>294</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>295</span> 
<span class='line'>296</span> </span><span class="COMM">/**
<span class='line'>297</span>  * convert a Base64 encoded string to a UTF-8 encoded string including CJK or Latin.&lt;br/>
<span class='line'>298</span>  * @name b64toutf8
<span class='line'>299</span>  * @function
<span class='line'>300</span>  * @param {String} s Base64 encoded string
<span class='line'>301</span>  * @return {String} UTF-8 encoded string
<span class='line'>302</span>  * @since 1.1.1
<span class='line'>303</span>  */</span><span class="WHIT">
<span class='line'>304</span> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">b64toutf8</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>305</span> </span><span class="WHIT">  </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">decodeURIComponent</span><span class="PUNC">(</span><span class="NAME">hextouricmp</span><span class="PUNC">(</span><span class="NAME">b64tohex</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>306</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>307</span> 
<span class='line'>308</span> </span><span class="COMM">// ==== utf8 / hex ================================</span><span class="WHIT">
<span class='line'>309</span> </span><span class="COMM">/**
<span class='line'>310</span>  * convert a UTF-8 encoded string including CJK or Latin to a hexadecimal encoded string.&lt;br/>
<span class='line'>311</span>  * @name utf8tohex
<span class='line'>312</span>  * @function
<span class='line'>313</span>  * @param {String} s UTF-8 encoded string
<span class='line'>314</span>  * @return {String} hexadecimal encoded string
<span class='line'>315</span>  * @since 1.1.1
<span class='line'>316</span>  */</span><span class="WHIT">
<span class='line'>317</span> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">utf8tohex</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>318</span> </span><span class="WHIT">  </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">uricmptohex</span><span class="PUNC">(</span><span class="NAME">encodeURIComponentAll</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>319</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>320</span> 
<span class='line'>321</span> </span><span class="COMM">/**
<span class='line'>322</span>  * convert a hexadecimal encoded string to a UTF-8 encoded string including CJK or Latin.&lt;br/>
<span class='line'>323</span>  * Note that when input is improper hexadecimal string as UTF-8 string, this function returns
<span class='line'>324</span>  * 'null'.
<span class='line'>325</span>  * @name hextoutf8
<span class='line'>326</span>  * @function
<span class='line'>327</span>  * @param {String} s hexadecimal encoded string
<span class='line'>328</span>  * @return {String} UTF-8 encoded string or null
<span class='line'>329</span>  * @since 1.1.1
<span class='line'>330</span>  */</span><span class="WHIT">
<span class='line'>331</span> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">hextoutf8</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>332</span> </span><span class="WHIT">  </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">decodeURIComponent</span><span class="PUNC">(</span><span class="NAME">hextouricmp</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>333</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>334</span> 
<span class='line'>335</span> </span><span class="COMM">/**
<span class='line'>336</span>  * convert a hexadecimal encoded string to raw string including non printable characters.&lt;br/>
<span class='line'>337</span>  * @name hextorstr
<span class='line'>338</span>  * @function
<span class='line'>339</span>  * @param {String} s hexadecimal encoded string
<span class='line'>340</span>  * @return {String} raw string
<span class='line'>341</span>  * @since 1.1.2
<span class='line'>342</span>  * @example
<span class='line'>343</span>  * hextorstr("610061") &rarr; "a\x00a"
<span class='line'>344</span>  */</span><span class="WHIT">
<span class='line'>345</span> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">hextorstr</span><span class="PUNC">(</span><span class="NAME">sHex</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>346</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">s</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">""</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>347</span> </span><span class="WHIT">    </span><span class="KEYW">for</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NAME">sHex.length</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NUMB">1</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>348</span> </span><span class="WHIT">        </span><span class="NAME">s</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">String.fromCharCode</span><span class="PUNC">(</span><span class="NAME">parseInt</span><span class="PUNC">(</span><span class="NAME">sHex.substr</span><span class="PUNC">(</span><span class="NAME">i</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">16</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>349</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>350</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">s</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>351</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>352</span> 
<span class='line'>353</span> </span><span class="COMM">/**
<span class='line'>354</span>  * convert a raw string including non printable characters to hexadecimal encoded string.&lt;br/>
<span class='line'>355</span>  * @name rstrtohex
<span class='line'>356</span>  * @function
<span class='line'>357</span>  * @param {String} s raw string
<span class='line'>358</span>  * @return {String} hexadecimal encoded string
<span class='line'>359</span>  * @since 1.1.2
<span class='line'>360</span>  * @example
<span class='line'>361</span>  * rstrtohex("a\x00a") &rarr; "610061"
<span class='line'>362</span>  */</span><span class="WHIT">
<span class='line'>363</span> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">rstrtohex</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>364</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">result</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">""</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>365</span> </span><span class="WHIT">    </span><span class="KEYW">for</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NAME">s.length</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="PUNC">++</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>366</span> </span><span class="WHIT">        </span><span class="NAME">result</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="STRN">"0"</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">s.charCodeAt</span><span class="PUNC">(</span><span class="NAME">i</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">toString</span><span class="PUNC">(</span><span class="NUMB">16</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">slice</span><span class="PUNC">(</span><span class="PUNC">-</span><span class="NUMB">2</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>367</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>368</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">result</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>369</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>370</span> 
<span class='line'>371</span> </span><span class="COMM">// ==== hex / b64nl =======================================</span><span class="WHIT">
<span class='line'>372</span> 
<span class='line'>373</span> </span><span class="COMM">/**
<span class='line'>374</span>  * convert a hexadecimal string to Base64 encoded string&lt;br/>
<span class='line'>375</span>  * @name hextob64
<span class='line'>376</span>  * @function
<span class='line'>377</span>  * @param {String} s hexadecimal string
<span class='line'>378</span>  * @return {String} resulted Base64 encoded string
<span class='line'>379</span>  * @since base64x 1.1.3
<span class='line'>380</span>  * @description
<span class='line'>381</span>  * This function converts from a hexadecimal string to Base64 encoded
<span class='line'>382</span>  * string without new lines.
<span class='line'>383</span>  * @example
<span class='line'>384</span>  * hextob64("616161") &rarr; "YWFh"
<span class='line'>385</span>  */</span><span class="WHIT">
<span class='line'>386</span> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">hextob64</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>387</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">hex2b64</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>388</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>389</span> 
<span class='line'>390</span> </span><span class="COMM">/**
<span class='line'>391</span>  * convert a hexadecimal string to Base64 encoded string with new lines&lt;br/>
<span class='line'>392</span>  * @name hextob64nl
<span class='line'>393</span>  * @function
<span class='line'>394</span>  * @param {String} s hexadecimal string
<span class='line'>395</span>  * @return {String} resulted Base64 encoded string with new lines
<span class='line'>396</span>  * @since base64x 1.1.3
<span class='line'>397</span>  * @description
<span class='line'>398</span>  * This function converts from a hexadecimal string to Base64 encoded
<span class='line'>399</span>  * string with new lines for each 64 characters. This is useful for
<span class='line'>400</span>  * PEM encoded file.
<span class='line'>401</span>  * @example
<span class='line'>402</span>  * hextob64nl("123456789012345678901234567890123456789012345678901234567890")
<span class='line'>403</span>  * &rarr;
<span class='line'>404</span>  * MTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4 // new line
<span class='line'>405</span>  * OTAxMjM0NTY3ODkwCg==
<span class='line'>406</span>  */</span><span class="WHIT">
<span class='line'>407</span> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">hextob64nl</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>408</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">b64</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">hextob64</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>409</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">b64nl</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">b64.replace</span><span class="PUNC">(</span><span class="REGX">/(.{64})/g</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"$1\r\n"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>410</span> </span><span class="WHIT">    </span><span class="NAME">b64nl</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">b64nl.replace</span><span class="PUNC">(</span><span class="REGX">/\r\n$/</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">''</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>411</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">b64nl</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>412</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>413</span> 
<span class='line'>414</span> </span><span class="COMM">/**
<span class='line'>415</span>  * convert a Base64 encoded string with new lines to a hexadecimal string&lt;br/>
<span class='line'>416</span>  * @name b64nltohex
<span class='line'>417</span>  * @function
<span class='line'>418</span>  * @param {String} s Base64 encoded string with new lines
<span class='line'>419</span>  * @return {String} hexadecimal string
<span class='line'>420</span>  * @since base64x 1.1.3
<span class='line'>421</span>  * @description
<span class='line'>422</span>  * This function converts from a Base64 encoded
<span class='line'>423</span>  * string with new lines to a hexadecimal string.
<span class='line'>424</span>  * This is useful to handle PEM encoded file.
<span class='line'>425</span>  * This function removes any non-Base64 characters (i.e. not 0-9,A-Z,a-z,\,+,=)
<span class='line'>426</span>  * including new line.
<span class='line'>427</span>  * @example
<span class='line'>428</span>  * hextob64nl(
<span class='line'>429</span>  * "MTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4\r\n" +
<span class='line'>430</span>  * "OTAxMjM0NTY3ODkwCg==\r\n")
<span class='line'>431</span>  * &rarr;
<span class='line'>432</span>  * "123456789012345678901234567890123456789012345678901234567890"
<span class='line'>433</span>  */</span><span class="WHIT">
<span class='line'>434</span> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">b64nltohex</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>435</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">b64</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">s.replace</span><span class="PUNC">(</span><span class="REGX">/[^0-9A-Za-z\/+=]*/g</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">''</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>436</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">hex</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">b64tohex</span><span class="PUNC">(</span><span class="NAME">b64</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>437</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">hex</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>438</span> </span><span class="PUNC">}</span><span class="WHIT"> 
<span class='line'>439</span> 
<span class='line'>440</span> </span><span class="COMM">// ==== hex / pem =========================================</span><span class="WHIT">
<span class='line'>441</span> 
<span class='line'>442</span> </span><span class="COMM">/**
<span class='line'>443</span>  * get PEM string from hexadecimal data and header string
<span class='line'>444</span>  * @name hextopem
<span class='line'>445</span>  * @function
<span class='line'>446</span>  * @param {String} dataHex hexadecimal string of PEM body
<span class='line'>447</span>  * @param {String} pemHeader PEM header string (ex. 'RSA PRIVATE KEY')
<span class='line'>448</span>  * @return {String} PEM formatted string of input data
<span class='line'>449</span>  * @since jsrasign 7.2.1 base64x 1.1.12
<span class='line'>450</span>  * @description
<span class='line'>451</span>  * This function converts a hexadecimal string to a PEM string with
<span class='line'>452</span>  * a specified header. Its line break will be CRLF("\r\n").
<span class='line'>453</span>  * @example
<span class='line'>454</span>  * hextopem('616161', 'RSA PRIVATE KEY') &rarr;
<span class='line'>455</span>  * -----BEGIN PRIVATE KEY-----
<span class='line'>456</span>  * YWFh
<span class='line'>457</span>  * -----END PRIVATE KEY-----
<span class='line'>458</span>  */</span><span class="WHIT">
<span class='line'>459</span> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">hextopem</span><span class="PUNC">(</span><span class="NAME">dataHex</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">pemHeader</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>460</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">pemBody</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">hextob64nl</span><span class="PUNC">(</span><span class="NAME">dataHex</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>461</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="STRN">"-----BEGIN "</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">pemHeader</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="STRN">"-----\r\n"</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> 
<span class='line'>462</span>         </span><span class="NAME">pemBody</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> 
<span class='line'>463</span>         </span><span class="STRN">"\r\n-----END "</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">pemHeader</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="STRN">"-----\r\n"</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>464</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>465</span> 
<span class='line'>466</span> </span><span class="COMM">/**
<span class='line'>467</span>  * get hexacedimal string from PEM format data&lt;br/>
<span class='line'>468</span>  * @name pemtohex
<span class='line'>469</span>  * @function
<span class='line'>470</span>  * @param {String} s PEM formatted string
<span class='line'>471</span>  * @param {String} sHead PEM header string without BEGIN/END(OPTION)
<span class='line'>472</span>  * @return {String} hexadecimal string data of PEM contents
<span class='line'>473</span>  * @since jsrsasign 7.2.1 base64x 1.1.12
<span class='line'>474</span>  * @description
<span class='line'>475</span>  * This static method gets a hexacedimal string of contents 
<span class='line'>476</span>  * from PEM format data. You can explicitly specify PEM header 
<span class='line'>477</span>  * by sHead argument. 
<span class='line'>478</span>  * Any space characters such as white space or new line
<span class='line'>479</span>  * will be omitted.&lt;br/>
<span class='line'>480</span>  * NOTE: Now {@link KEYUTIL.getHexFromPEM} and {@link X509.pemToHex}
<span class='line'>481</span>  * have been deprecated since jsrsasign 7.2.1. 
<span class='line'>482</span>  * Please use this method instead.
<span class='line'>483</span>  * @example
<span class='line'>484</span>  * pemtohex("-----BEGIN PUBLIC KEY...") &rarr; "3082..."
<span class='line'>485</span>  * pemtohex("-----BEGIN CERTIFICATE...", "CERTIFICATE") &rarr; "3082..."
<span class='line'>486</span>  * pemtohex(" \r\n-----BEGIN DSA PRIVATE KEY...") &rarr; "3082..."
<span class='line'>487</span>  */</span><span class="WHIT">
<span class='line'>488</span> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">pemtohex</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">sHead</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>489</span> </span><span class="WHIT">    </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">s.indexOf</span><span class="PUNC">(</span><span class="STRN">"-----BEGIN "</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="NUMB">1</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>490</span> </span><span class="WHIT">        </span><span class="KEYW">throw</span><span class="WHIT"> </span><span class="STRN">"can't find PEM header: "</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">sHead</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>491</span> 
<span class='line'>492</span> </span><span class="WHIT">    </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">sHead</span><span class="WHIT"> </span><span class="PUNC">!==</span><span class="WHIT"> </span><span class="NAME">undefined</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>493</span> </span><span class="WHIT">        </span><span class="NAME">s</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">s.replace</span><span class="PUNC">(</span><span class="STRN">"-----BEGIN "</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">sHead</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="STRN">"-----"</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">""</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>494</span> </span><span class="WHIT">        </span><span class="NAME">s</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">s.replace</span><span class="PUNC">(</span><span class="STRN">"-----END "</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">sHead</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="STRN">"-----"</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">""</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>495</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT"> </span><span class="KEYW">else</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>496</span> </span><span class="WHIT">        </span><span class="NAME">s</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">s.replace</span><span class="PUNC">(</span><span class="REGX">/-----BEGIN [^-]+-----/</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">''</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>497</span> </span><span class="WHIT">        </span><span class="NAME">s</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">s.replace</span><span class="PUNC">(</span><span class="REGX">/-----END [^-]+-----/</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">''</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>498</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>499</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">b64nltohex</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>500</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>501</span> 
<span class='line'>502</span> </span><span class="COMM">// ==== hex / ArrayBuffer =================================</span><span class="WHIT">
<span class='line'>503</span> 
<span class='line'>504</span> </span><span class="COMM">/**
<span class='line'>505</span>  * convert a hexadecimal string to an ArrayBuffer&lt;br/>
<span class='line'>506</span>  * @name hextoArrayBuffer
<span class='line'>507</span>  * @function
<span class='line'>508</span>  * @param {String} hex hexadecimal string
<span class='line'>509</span>  * @return {ArrayBuffer} ArrayBuffer
<span class='line'>510</span>  * @since jsrsasign 6.1.4 base64x 1.1.8
<span class='line'>511</span>  * @description
<span class='line'>512</span>  * This function converts from a hexadecimal string to an ArrayBuffer.
<span class='line'>513</span>  * @example
<span class='line'>514</span>  * hextoArrayBuffer("fffa01") &rarr; ArrayBuffer of [255, 250, 1]
<span class='line'>515</span>  */</span><span class="WHIT">
<span class='line'>516</span> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">hextoArrayBuffer</span><span class="PUNC">(</span><span class="NAME">hex</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>517</span> </span><span class="WHIT">    </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">hex.length</span><span class="WHIT"> </span><span class="PUNC">%</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="WHIT"> </span><span class="PUNC">!=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="KEYW">throw</span><span class="WHIT"> </span><span class="STRN">"input is not even length"</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>518</span> </span><span class="WHIT">    </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">hex.match</span><span class="PUNC">(</span><span class="REGX">/^[0-9A-Fa-f]+$/</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="KEYW">throw</span><span class="WHIT"> </span><span class="STRN">"input is not hexadecimal"</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>519</span> 
<span class='line'>520</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">buffer</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">ArrayBuffer</span><span class="PUNC">(</span><span class="NAME">hex.length</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>521</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">view</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">DataView</span><span class="PUNC">(</span><span class="NAME">buffer</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>522</span> 
<span class='line'>523</span> </span><span class="WHIT">    </span><span class="KEYW">for</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NAME">hex.length</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="PUNC">++</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>524</span> </span><span class="WHIT">	</span><span class="NAME">view.setUint8</span><span class="PUNC">(</span><span class="NAME">i</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">parseInt</span><span class="PUNC">(</span><span class="NAME">hex.substr</span><span class="PUNC">(</span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">16</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>525</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>526</span> 
<span class='line'>527</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">buffer</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>528</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>529</span> 
<span class='line'>530</span> </span><span class="COMM">// ==== ArrayBuffer / hex =================================</span><span class="WHIT">
<span class='line'>531</span> 
<span class='line'>532</span> </span><span class="COMM">/**
<span class='line'>533</span>  * convert an ArrayBuffer to a hexadecimal string&lt;br/>
<span class='line'>534</span>  * @name ArrayBuffertohex
<span class='line'>535</span>  * @function
<span class='line'>536</span>  * @param {ArrayBuffer} buffer ArrayBuffer
<span class='line'>537</span>  * @return {String} hexadecimal string
<span class='line'>538</span>  * @since jsrsasign 6.1.4 base64x 1.1.8
<span class='line'>539</span>  * @description
<span class='line'>540</span>  * This function converts from an ArrayBuffer to a hexadecimal string.
<span class='line'>541</span>  * @example
<span class='line'>542</span>  * var buffer = new ArrayBuffer(3);
<span class='line'>543</span>  * var view = new DataView(buffer);
<span class='line'>544</span>  * view.setUint8(0, 0xfa);
<span class='line'>545</span>  * view.setUint8(1, 0xfb);
<span class='line'>546</span>  * view.setUint8(2, 0x01);
<span class='line'>547</span>  * ArrayBuffertohex(buffer) &rarr; "fafb01"
<span class='line'>548</span>  */</span><span class="WHIT">
<span class='line'>549</span> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">ArrayBuffertohex</span><span class="PUNC">(</span><span class="NAME">buffer</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>550</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">hex</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">""</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>551</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">view</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">DataView</span><span class="PUNC">(</span><span class="NAME">buffer</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>552</span> 
<span class='line'>553</span> </span><span class="WHIT">    </span><span class="KEYW">for</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NAME">buffer.byteLength</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="PUNC">++</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>554</span> </span><span class="WHIT">	</span><span class="NAME">hex</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="STRN">"00"</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">view.getUint8</span><span class="PUNC">(</span><span class="NAME">i</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">toString</span><span class="PUNC">(</span><span class="NUMB">16</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">slice</span><span class="PUNC">(</span><span class="PUNC">-</span><span class="NUMB">2</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>555</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>556</span> 
<span class='line'>557</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">hex</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>558</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>559</span> 
<span class='line'>560</span> </span><span class="COMM">// ==== zulu / int =================================</span><span class="WHIT">
<span class='line'>561</span> </span><span class="COMM">/**
<span class='line'>562</span>  * GeneralizedTime or UTCTime string to milliseconds from Unix origin&lt;br>
<span class='line'>563</span>  * @name zulutomsec
<span class='line'>564</span>  * @function
<span class='line'>565</span>  * @param {String} s GeneralizedTime or UTCTime string (ex. 20170412235959.384Z)
<span class='line'>566</span>  * @return {Number} milliseconds from Unix origin time (i.e. Jan 1, 1970 0:00:00 UTC)
<span class='line'>567</span>  * @since jsrsasign 7.1.3 base64x 1.1.9
<span class='line'>568</span>  * @description
<span class='line'>569</span>  * This function converts from GeneralizedTime string (i.e. YYYYMMDDHHmmSSZ) or
<span class='line'>570</span>  * UTCTime string (i.e. YYMMDDHHmmSSZ) to milliseconds from Unix origin time
<span class='line'>571</span>  * (i.e. Jan 1 1970 0:00:00 UTC). 
<span class='line'>572</span>  * Argument string may have fraction of seconds and
<span class='line'>573</span>  * its length is one or more digits such as "20170410235959.1234567Z".
<span class='line'>574</span>  * As for UTCTime, if year "YY" is equal or less than 49 then it is 20YY.
<span class='line'>575</span>  * If year "YY" is equal or greater than 50 then it is 19YY.
<span class='line'>576</span>  * @example
<span class='line'>577</span>  * zulutomsec(  "071231235959Z")       &rarr; 1199145599000 #Mon, 31 Dec 2007 23:59:59 GMT
<span class='line'>578</span>  * zulutomsec(  "071231235959.1Z")     &rarr; 1199145599100 #Mon, 31 Dec 2007 23:59:59 GMT
<span class='line'>579</span>  * zulutomsec(  "071231235959.12345Z") &rarr; 1199145599123 #Mon, 31 Dec 2007 23:59:59 GMT
<span class='line'>580</span>  * zulutomsec("20071231235959Z")       &rarr; 1199145599000 #Mon, 31 Dec 2007 23:59:59 GMT
<span class='line'>581</span>  * zulutomsec(  "931231235959Z")       &rarr; -410227201000 #Mon, 31 Dec 1956 23:59:59 GMT
<span class='line'>582</span>  */</span><span class="WHIT">
<span class='line'>583</span> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">zulutomsec</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>584</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">year</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">month</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">day</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">hour</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">min</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">sec</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">msec</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">d</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>585</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">sYear</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">sFrac</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">sMsec</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">matchResult</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>586</span> 
<span class='line'>587</span> </span><span class="WHIT">    </span><span class="NAME">matchResult</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">s.match</span><span class="PUNC">(</span><span class="REGX">/^(\d{2}|\d{4})(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(|\.\d+)Z$/</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>588</span> 
<span class='line'>589</span> </span><span class="WHIT">    </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">matchResult</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>590</span> </span><span class="WHIT">        </span><span class="NAME">sYear</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">matchResult</span><span class="PUNC">[</span><span class="NUMB">1</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>591</span> </span><span class="WHIT">	</span><span class="NAME">year</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">parseInt</span><span class="PUNC">(</span><span class="NAME">sYear</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>592</span> </span><span class="WHIT">        </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">sYear.length</span><span class="WHIT"> </span><span class="PUNC">===</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>593</span> </span><span class="WHIT">	    </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NUMB">50</span><span class="WHIT"> </span><span class="PUNC">&lt;=</span><span class="WHIT"> </span><span class="NAME">year</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT"> </span><span class="NAME">year</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NUMB">100</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>594</span> </span><span class="WHIT">		</span><span class="NAME">year</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">1900</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">year</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>595</span> </span><span class="WHIT">	    </span><span class="PUNC">}</span><span class="WHIT"> </span><span class="KEYW">else</span><span class="WHIT"> </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NUMB">0</span><span class="WHIT"> </span><span class="PUNC">&lt;=</span><span class="WHIT"> </span><span class="NAME">year</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT"> </span><span class="NAME">year</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NUMB">50</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>596</span> </span><span class="WHIT">		</span><span class="NAME">year</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">2000</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">year</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>597</span> </span><span class="WHIT">	    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>598</span> </span><span class="WHIT">	</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>599</span> </span><span class="WHIT">	</span><span class="NAME">month</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">parseInt</span><span class="PUNC">(</span><span class="NAME">matchResult</span><span class="PUNC">[</span><span class="NUMB">2</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NUMB">1</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>600</span> </span><span class="WHIT">	</span><span class="NAME">day</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">parseInt</span><span class="PUNC">(</span><span class="NAME">matchResult</span><span class="PUNC">[</span><span class="NUMB">3</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>601</span> </span><span class="WHIT">	</span><span class="NAME">hour</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">parseInt</span><span class="PUNC">(</span><span class="NAME">matchResult</span><span class="PUNC">[</span><span class="NUMB">4</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>602</span> </span><span class="WHIT">	</span><span class="NAME">min</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">parseInt</span><span class="PUNC">(</span><span class="NAME">matchResult</span><span class="PUNC">[</span><span class="NUMB">5</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>603</span> </span><span class="WHIT">	</span><span class="NAME">sec</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">parseInt</span><span class="PUNC">(</span><span class="NAME">matchResult</span><span class="PUNC">[</span><span class="NUMB">6</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>604</span> </span><span class="WHIT">	</span><span class="NAME">msec</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>605</span> 
<span class='line'>606</span> </span><span class="WHIT">	</span><span class="NAME">sFrac</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">matchResult</span><span class="PUNC">[</span><span class="NUMB">7</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>607</span> </span><span class="WHIT">	</span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">sFrac</span><span class="WHIT"> </span><span class="PUNC">!==</span><span class="WHIT"> </span><span class="STRN">""</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>608</span> </span><span class="WHIT">	    </span><span class="NAME">sMsec</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">sFrac.substr</span><span class="PUNC">(</span><span class="NUMB">1</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="STRN">"00"</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">substr</span><span class="PUNC">(</span><span class="NUMB">0</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">3</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="COMM">// .12 -> 012</span><span class="WHIT">
<span class='line'>609</span> </span><span class="WHIT">	    </span><span class="NAME">msec</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">parseInt</span><span class="PUNC">(</span><span class="NAME">sMsec</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>610</span> </span><span class="WHIT">	</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>611</span> </span><span class="WHIT">	</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">Date.UTC</span><span class="PUNC">(</span><span class="NAME">year</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">month</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">day</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">hour</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">min</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">sec</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">msec</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>612</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>613</span> </span><span class="WHIT">    </span><span class="KEYW">throw</span><span class="WHIT"> </span><span class="STRN">"unsupported zulu format: "</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">s</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>614</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>615</span> 
<span class='line'>616</span> </span><span class="COMM">/**
<span class='line'>617</span>  * GeneralizedTime or UTCTime string to seconds from Unix origin&lt;br>
<span class='line'>618</span>  * @name zulutosec
<span class='line'>619</span>  * @function
<span class='line'>620</span>  * @param {String} s GeneralizedTime or UTCTime string (ex. 20170412235959.384Z)
<span class='line'>621</span>  * @return {Number} seconds from Unix origin time (i.e. Jan 1, 1970 0:00:00 UTC)
<span class='line'>622</span>  * @since jsrsasign 7.1.3 base64x 1.1.9
<span class='line'>623</span>  * @description
<span class='line'>624</span>  * This function converts from GeneralizedTime string (i.e. YYYYMMDDHHmmSSZ) or
<span class='line'>625</span>  * UTCTime string (i.e. YYMMDDHHmmSSZ) to seconds from Unix origin time
<span class='line'>626</span>  * (i.e. Jan 1 1970 0:00:00 UTC). Argument string may have fraction of seconds 
<span class='line'>627</span>  * however result value will be omitted.
<span class='line'>628</span>  * As for UTCTime, if year "YY" is equal or less than 49 then it is 20YY.
<span class='line'>629</span>  * If year "YY" is equal or greater than 50 then it is 19YY.
<span class='line'>630</span>  * @example
<span class='line'>631</span>  * zulutosec(  "071231235959Z")       &rarr; 1199145599 #Mon, 31 Dec 2007 23:59:59 GMT
<span class='line'>632</span>  * zulutosec(  "071231235959.1Z")     &rarr; 1199145599 #Mon, 31 Dec 2007 23:59:59 GMT
<span class='line'>633</span>  * zulutosec("20071231235959Z")       &rarr; 1199145599 #Mon, 31 Dec 2007 23:59:59 GMT
<span class='line'>634</span>  */</span><span class="WHIT">
<span class='line'>635</span> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">zulutosec</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>636</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">msec</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">zulutomsec</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>637</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="PUNC">~</span><span class="PUNC">~</span><span class="PUNC">(</span><span class="NAME">msec</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NUMB">1000</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>638</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>639</span> 
<span class='line'>640</span> </span><span class="COMM">// ==== zulu / Date =================================</span><span class="WHIT">
<span class='line'>641</span> 
<span class='line'>642</span> </span><span class="COMM">/**
<span class='line'>643</span>  * GeneralizedTime or UTCTime string to Date object&lt;br>
<span class='line'>644</span>  * @name zulutodate
<span class='line'>645</span>  * @function
<span class='line'>646</span>  * @param {String} s GeneralizedTime or UTCTime string (ex. 20170412235959.384Z)
<span class='line'>647</span>  * @return {Date} Date object for specified time
<span class='line'>648</span>  * @since jsrsasign 7.1.3 base64x 1.1.9
<span class='line'>649</span>  * @description
<span class='line'>650</span>  * This function converts from GeneralizedTime string (i.e. YYYYMMDDHHmmSSZ) or
<span class='line'>651</span>  * UTCTime string (i.e. YYMMDDHHmmSSZ) to Date object.
<span class='line'>652</span>  * Argument string may have fraction of seconds and
<span class='line'>653</span>  * its length is one or more digits such as "20170410235959.1234567Z".
<span class='line'>654</span>  * As for UTCTime, if year "YY" is equal or less than 49 then it is 20YY.
<span class='line'>655</span>  * If year "YY" is equal or greater than 50 then it is 19YY.
<span class='line'>656</span>  * @example
<span class='line'>657</span>  * zulutodate(  "071231235959Z").toUTCString()   &rarr; "Mon, 31 Dec 2007 23:59:59 GMT"
<span class='line'>658</span>  * zulutodate(  "071231235959.1Z").toUTCString() &rarr; "Mon, 31 Dec 2007 23:59:59 GMT"
<span class='line'>659</span>  * zulutodate("20071231235959Z").toUTCString()   &rarr; "Mon, 31 Dec 2007 23:59:59 GMT"
<span class='line'>660</span>  * zulutodate(  "071231235959.34").getMilliseconds() &rarr; 340
<span class='line'>661</span>  */</span><span class="WHIT">
<span class='line'>662</span> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">zulutodate</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>663</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">Date</span><span class="PUNC">(</span><span class="NAME">zulutomsec</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>664</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>665</span> 
<span class='line'>666</span> </span><span class="COMM">// ==== Date / zulu =================================</span><span class="WHIT">
<span class='line'>667</span> 
<span class='line'>668</span> </span><span class="COMM">/**
<span class='line'>669</span>  * Date object to zulu time string&lt;br>
<span class='line'>670</span>  * @name datetozulu
<span class='line'>671</span>  * @function
<span class='line'>672</span>  * @param {Date} d Date object for specified time
<span class='line'>673</span>  * @param {Boolean} flagUTCTime if this is true year will be YY otherwise YYYY
<span class='line'>674</span>  * @param {Boolean} flagMilli if this is true result concludes milliseconds
<span class='line'>675</span>  * @return {String} GeneralizedTime or UTCTime string (ex. 20170412235959.384Z)
<span class='line'>676</span>  * @since jsrsasign 7.2.0 base64x 1.1.11
<span class='line'>677</span>  * @description
<span class='line'>678</span>  * This function converts from Date object to GeneralizedTime string (i.e. YYYYMMDDHHmmSSZ) or
<span class='line'>679</span>  * UTCTime string (i.e. YYMMDDHHmmSSZ).
<span class='line'>680</span>  * As for UTCTime, if year "YY" is equal or less than 49 then it is 20YY.
<span class='line'>681</span>  * If year "YY" is equal or greater than 50 then it is 19YY.
<span class='line'>682</span>  * If flagMilli is true its result concludes milliseconds such like
<span class='line'>683</span>  * "20170520235959.42Z". 
<span class='line'>684</span>  * @example
<span class='line'>685</span>  * d = new Date(Date.UTC(2017,4,20,23,59,59,670));
<span class='line'>686</span>  * datetozulu(d) &rarr; "20170520235959Z"
<span class='line'>687</span>  * datetozulu(d, true) &rarr; "170520235959Z"
<span class='line'>688</span>  * datetozulu(d, false, true) &rarr; "20170520235959.67Z"
<span class='line'>689</span>  */</span><span class="WHIT">
<span class='line'>690</span> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">datetozulu</span><span class="PUNC">(</span><span class="NAME">d</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">flagUTCTime</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">flagMilli</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>691</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">s</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>692</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">year</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">d.getUTCFullYear</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>693</span> </span><span class="WHIT">    </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">flagUTCTime</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>694</span> </span><span class="WHIT">	</span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">year</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NUMB">1950</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NUMB">2049</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NAME">year</span><span class="PUNC">)</span><span class="WHIT"> 
<span class='line'>695</span> 	    </span><span class="KEYW">throw</span><span class="WHIT"> </span><span class="STRN">"not proper year for UTCTime: "</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">year</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>696</span> </span><span class="WHIT">	</span><span class="NAME">s</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="STRN">""</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">year</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">slice</span><span class="PUNC">(</span><span class="PUNC">-</span><span class="NUMB">2</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>697</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT"> </span><span class="KEYW">else</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>698</span> </span><span class="WHIT">	</span><span class="NAME">s</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="STRN">"000"</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">year</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">slice</span><span class="PUNC">(</span><span class="PUNC">-</span><span class="NUMB">4</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>699</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>700</span> </span><span class="WHIT">    </span><span class="NAME">s</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="STRN">"0"</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">d.getUTCMonth</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NUMB">1</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">slice</span><span class="PUNC">(</span><span class="PUNC">-</span><span class="NUMB">2</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>701</span> </span><span class="WHIT">    </span><span class="NAME">s</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="STRN">"0"</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">d.getUTCDate</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">slice</span><span class="PUNC">(</span><span class="PUNC">-</span><span class="NUMB">2</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>702</span> </span><span class="WHIT">    </span><span class="NAME">s</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="STRN">"0"</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">d.getUTCHours</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">slice</span><span class="PUNC">(</span><span class="PUNC">-</span><span class="NUMB">2</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>703</span> </span><span class="WHIT">    </span><span class="NAME">s</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="STRN">"0"</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">d.getUTCMinutes</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">slice</span><span class="PUNC">(</span><span class="PUNC">-</span><span class="NUMB">2</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>704</span> </span><span class="WHIT">    </span><span class="NAME">s</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="STRN">"0"</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">d.getUTCSeconds</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">slice</span><span class="PUNC">(</span><span class="PUNC">-</span><span class="NUMB">2</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>705</span> </span><span class="WHIT">    </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">flagMilli</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>706</span> </span><span class="WHIT">	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">milli</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">d.getUTCMilliseconds</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>707</span> </span><span class="WHIT">	</span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">milli</span><span class="WHIT"> </span><span class="PUNC">!==</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>708</span> </span><span class="WHIT">	    </span><span class="NAME">milli</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="STRN">"00"</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">milli</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">slice</span><span class="PUNC">(</span><span class="PUNC">-</span><span class="NUMB">3</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>709</span> </span><span class="WHIT">	    </span><span class="NAME">milli</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">milli.replace</span><span class="PUNC">(</span><span class="REGX">/0+$/g</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">""</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>710</span> </span><span class="WHIT">	    </span><span class="NAME">s</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">"."</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">milli</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>711</span> </span><span class="WHIT">	</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>712</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>713</span> </span><span class="WHIT">    </span><span class="NAME">s</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">"Z"</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>714</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">s</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>715</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>716</span> 
<span class='line'>717</span> </span><span class="COMM">// ==== URIComponent / hex ================================</span><span class="WHIT">
<span class='line'>718</span> </span><span class="COMM">/**
<span class='line'>719</span>  * convert a URLComponent string such like "%67%68" to a hexadecimal string.&lt;br/>
<span class='line'>720</span>  * @name uricmptohex
<span class='line'>721</span>  * @function
<span class='line'>722</span>  * @param {String} s URIComponent string such like "%67%68"
<span class='line'>723</span>  * @return {String} hexadecimal string
<span class='line'>724</span>  * @since 1.1
<span class='line'>725</span>  */</span><span class="WHIT">
<span class='line'>726</span> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">uricmptohex</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>727</span> </span><span class="WHIT">  </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">s.replace</span><span class="PUNC">(</span><span class="REGX">/%/g</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">""</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>728</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>729</span> 
<span class='line'>730</span> </span><span class="COMM">/**
<span class='line'>731</span>  * convert a hexadecimal string to a URLComponent string such like "%67%68".&lt;br/>
<span class='line'>732</span>  * @name hextouricmp
<span class='line'>733</span>  * @function
<span class='line'>734</span>  * @param {String} s hexadecimal string
<span class='line'>735</span>  * @return {String} URIComponent string such like "%67%68"
<span class='line'>736</span>  * @since 1.1
<span class='line'>737</span>  */</span><span class="WHIT">
<span class='line'>738</span> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">hextouricmp</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>739</span> </span><span class="WHIT">  </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">s.replace</span><span class="PUNC">(</span><span class="REGX">/(..)/g</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"%$1"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>740</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>741</span> 
<span class='line'>742</span> </span><span class="COMM">// ==== hex / ipv6 =================================</span><span class="WHIT">
<span class='line'>743</span> 
<span class='line'>744</span> </span><span class="COMM">/**
<span class='line'>745</span>  * convert any IPv6 address to a 16 byte hexadecimal string
<span class='line'>746</span>  * @function
<span class='line'>747</span>  * @param s string of IPv6 address
<span class='line'>748</span>  * @return {String} 16 byte hexadecimal string of IPv6 address
<span class='line'>749</span>  * @description
<span class='line'>750</span>  * This function converts any IPv6 address representation string
<span class='line'>751</span>  * to a 16 byte hexadecimal string of address.
<span class='line'>752</span>  * @example
<span class='line'>753</span>  * 
<span class='line'>754</span>  */</span><span class="WHIT">
<span class='line'>755</span> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">ipv6tohex</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>756</span> </span><span class="WHIT">  </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">msgMalformedAddress</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">"malformed IPv6 address"</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>757</span> </span><span class="WHIT">  </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">!</span><span class="WHIT"> </span><span class="NAME">s.match</span><span class="PUNC">(</span><span class="REGX">/^[0-9A-Fa-f:]+$/</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>758</span> </span><span class="WHIT">    </span><span class="KEYW">throw</span><span class="WHIT"> </span><span class="NAME">msgMalformedAddress</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>759</span> 
<span class='line'>760</span> </span><span class="WHIT">  </span><span class="COMM">// 1. downcase</span><span class="WHIT">
<span class='line'>761</span> </span><span class="WHIT">  </span><span class="NAME">s</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">s.toLowerCase</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>762</span> 
<span class='line'>763</span> </span><span class="WHIT">  </span><span class="COMM">// 2. expand ::</span><span class="WHIT">
<span class='line'>764</span> </span><span class="WHIT">  </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">num_colon</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">s.split</span><span class="PUNC">(</span><span class="STRN">':'</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">length</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NUMB">1</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>765</span> </span><span class="WHIT">  </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">num_colon</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="KEYW">throw</span><span class="WHIT"> </span><span class="NAME">msgMalformedAddress</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>766</span> </span><span class="WHIT">  </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">colon_replacer</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">':'</span><span class="PUNC">.</span><span class="NAME">repeat</span><span class="PUNC">(</span><span class="NUMB">7</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NAME">num_colon</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>767</span> </span><span class="WHIT">  </span><span class="NAME">s</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">s.replace</span><span class="PUNC">(</span><span class="STRN">'::'</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">colon_replacer</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>768</span> 
<span class='line'>769</span> </span><span class="WHIT">  </span><span class="COMM">// 3. fill zero</span><span class="WHIT">
<span class='line'>770</span> </span><span class="WHIT">  </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">a</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">s.split</span><span class="PUNC">(</span><span class="STRN">':'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>771</span> </span><span class="WHIT">  </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">a.length</span><span class="WHIT"> </span><span class="PUNC">!=</span><span class="WHIT"> </span><span class="NUMB">8</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="KEYW">throw</span><span class="WHIT"> </span><span class="NAME">msgMalformedAddress</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>772</span> </span><span class="WHIT">  </span><span class="KEYW">for</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NUMB">8</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="PUNC">++</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>773</span> </span><span class="WHIT">    </span><span class="NAME">a</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="STRN">"0000"</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">a</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">slice</span><span class="PUNC">(</span><span class="PUNC">-</span><span class="NUMB">4</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>774</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>775</span> </span><span class="WHIT">  </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">a.join</span><span class="PUNC">(</span><span class="STRN">''</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>776</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>777</span> 
<span class='line'>778</span> </span><span class="COMM">/**
<span class='line'>779</span>  * convert a 16 byte hexadecimal string to RFC 5952 canonicalized IPv6 address&lt;br/>
<span class='line'>780</span>  * @name hextoipv6
<span class='line'>781</span>  * @function
<span class='line'>782</span>  * @param {String} s hexadecimal string of 16 byte IPv6 address
<span class='line'>783</span>  * @return {String} IPv6 address string canonicalized by RFC 5952
<span class='line'>784</span>  * @since jsrsasign 8.0.10 base64x 1.1.13
<span class='line'>785</span>  * @description
<span class='line'>786</span>  * This function converts a 16 byte hexadecimal string to 
<span class='line'>787</span>  * &lt;a href="https://tools.ietf.org/html/rfc5952">RFC 5952&lt;/a>
<span class='line'>788</span>  * canonicalized IPv6 address string.
<span class='line'>789</span>  * @example
<span class='line'>790</span>  * hextoip("871020010db8000000000000000000000004") &rarr "2001:db8::4"
<span class='line'>791</span>  * hextoip("871020010db8000000000000000000") &rarr raise exception
<span class='line'>792</span>  * hextoip("xyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyz") &rarr raise exception
<span class='line'>793</span>  */</span><span class="WHIT">
<span class='line'>794</span> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">hextoipv6</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>795</span> </span><span class="WHIT">  </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">!</span><span class="WHIT"> </span><span class="NAME">s.match</span><span class="PUNC">(</span><span class="REGX">/^[0-9A-Fa-f]{32}$/</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>796</span> </span><span class="WHIT">    </span><span class="KEYW">throw</span><span class="WHIT"> </span><span class="STRN">"malformed IPv6 address octet"</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>797</span> 
<span class='line'>798</span> </span><span class="WHIT">  </span><span class="COMM">// 1. downcase</span><span class="WHIT">
<span class='line'>799</span> </span><span class="WHIT">  </span><span class="NAME">s</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">s.toLowerCase</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>800</span> 
<span class='line'>801</span> </span><span class="WHIT">  </span><span class="COMM">// 2. split 4</span><span class="WHIT">
<span class='line'>802</span> </span><span class="WHIT">  </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">a</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">s.match</span><span class="PUNC">(</span><span class="REGX">/.{1,4}/g</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>803</span> 
<span class='line'>804</span> </span><span class="WHIT">  </span><span class="COMM">// 3. trim leading 0</span><span class="WHIT">
<span class='line'>805</span> </span><span class="WHIT">  </span><span class="KEYW">for</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NUMB">8</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="PUNC">++</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>806</span> </span><span class="WHIT">    </span><span class="NAME">a</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">a</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">.</span><span class="NAME">replace</span><span class="PUNC">(</span><span class="REGX">/^0+/</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">""</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>807</span> </span><span class="WHIT">    </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">a</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="STRN">''</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="NAME">a</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">'0'</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>808</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>809</span> </span><span class="WHIT">  </span><span class="NAME">s</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">":"</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">a.join</span><span class="PUNC">(</span><span class="STRN">":"</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="STRN">":"</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>810</span> 
<span class='line'>811</span> </span><span class="WHIT">  </span><span class="COMM">// 4. find shrinkables :0:0:...</span><span class="WHIT">
<span class='line'>812</span> </span><span class="WHIT">  </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">aZero</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">s.match</span><span class="PUNC">(</span><span class="REGX">/:(0:){2,}/g</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>813</span> 
<span class='line'>814</span> </span><span class="WHIT">  </span><span class="COMM">// 5. no shrinkable</span><span class="WHIT">
<span class='line'>815</span> </span><span class="WHIT">  </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">aZero</span><span class="WHIT"> </span><span class="PUNC">===</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">s.slice</span><span class="PUNC">(</span><span class="NUMB">1</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="NUMB">1</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>816</span> 
<span class='line'>817</span> </span><span class="WHIT">  </span><span class="COMM">// 6. find max length :0:0:...</span><span class="WHIT">
<span class='line'>818</span> </span><span class="WHIT">  </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">item</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">''</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>819</span> </span><span class="WHIT">  </span><span class="KEYW">for</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NAME">aZero.length</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="PUNC">++</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>820</span> </span><span class="WHIT">    </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">aZero</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">.</span><span class="NAME">length</span><span class="WHIT"> </span><span class="PUNC">></span><span class="WHIT"> </span><span class="NAME">item.length</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="NAME">item</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">aZero</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>821</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>822</span> 
<span class='line'>823</span> </span><span class="WHIT">  </span><span class="COMM">// 7. shrink</span><span class="WHIT">
<span class='line'>824</span> </span><span class="WHIT">  </span><span class="NAME">s</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">s.replace</span><span class="PUNC">(</span><span class="NAME">item</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">'::'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>825</span> </span><span class="WHIT">  </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">s.slice</span><span class="PUNC">(</span><span class="NUMB">1</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="NUMB">1</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>826</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>827</span> 
<span class='line'>828</span> </span><span class="COMM">// ==== hex / ip =================================</span><span class="WHIT">
<span class='line'>829</span> 
<span class='line'>830</span> </span><span class="COMM">/**
<span class='line'>831</span>  * convert a hexadecimal string to IP addresss&lt;br/>
<span class='line'>832</span>  * @name hextoip
<span class='line'>833</span>  * @function
<span class='line'>834</span>  * @param {String} s hexadecimal string of IP address
<span class='line'>835</span>  * @return {String} IP address string
<span class='line'>836</span>  * @since jsrsasign 8.0.10 base64x 1.1.13
<span class='line'>837</span>  * @description
<span class='line'>838</span>  * This function converts a hexadecimal string of IPv4 or 
<span class='line'>839</span>  * IPv6 address to IPv4 or IPv6 address string.
<span class='line'>840</span>  * If byte length is not 4 nor 16, this returns a
<span class='line'>841</span>  * hexadecimal string without conversion.
<span class='line'>842</span>  * @see {@link hextoipv6}
<span class='line'>843</span>  * @example
<span class='line'>844</span>  * hextoip("c0a80101") &rarr "192.168.1.1"
<span class='line'>845</span>  * hextoip("871020010db8000000000000000000000004") &rarr "2001:db8::4"
<span class='line'>846</span>  * hextoip("c0a801010203") &rarr "c0a801010203" // 6 bytes
<span class='line'>847</span>  * hextoip("zzz")) &rarr raise exception because of not hexadecimal
<span class='line'>848</span>  */</span><span class="WHIT">
<span class='line'>849</span> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">hextoip</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>850</span> </span><span class="WHIT">  </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">malformedMsg</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">"malformed hex value"</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>851</span> </span><span class="WHIT">  </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">!</span><span class="WHIT"> </span><span class="NAME">s.match</span><span class="PUNC">(</span><span class="REGX">/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>852</span> </span><span class="WHIT">    </span><span class="KEYW">throw</span><span class="WHIT"> </span><span class="NAME">malformedMsg</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>853</span> </span><span class="WHIT">  </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">s.length</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="NUMB">8</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="COMM">// ipv4</span><span class="WHIT">
<span class='line'>854</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">ip</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>855</span> </span><span class="WHIT">    </span><span class="KEYW">try</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>856</span> </span><span class="WHIT">      </span><span class="NAME">ip</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">parseInt</span><span class="PUNC">(</span><span class="NAME">s.substr</span><span class="PUNC">(</span><span class="NUMB">0</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">16</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="STRN">"."</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT">
<span class='line'>857</span> </span><span class="WHIT">           </span><span class="NAME">parseInt</span><span class="PUNC">(</span><span class="NAME">s.substr</span><span class="PUNC">(</span><span class="NUMB">2</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">16</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="STRN">"."</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT">
<span class='line'>858</span> </span><span class="WHIT">           </span><span class="NAME">parseInt</span><span class="PUNC">(</span><span class="NAME">s.substr</span><span class="PUNC">(</span><span class="NUMB">4</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">16</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="STRN">"."</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT">
<span class='line'>859</span> </span><span class="WHIT">           </span><span class="NAME">parseInt</span><span class="PUNC">(</span><span class="NAME">s.substr</span><span class="PUNC">(</span><span class="NUMB">6</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">16</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>860</span> </span><span class="WHIT">      </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">ip</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>861</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT"> </span><span class="KEYW">catch</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">ex</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>862</span> </span><span class="WHIT">      </span><span class="KEYW">throw</span><span class="WHIT"> </span><span class="NAME">malformedMsg</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>863</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>864</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="WHIT"> </span><span class="KEYW">else</span><span class="WHIT"> </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">s.length</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="NUMB">32</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>865</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">hextoipv6</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>866</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="WHIT"> </span><span class="KEYW">else</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>867</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">s</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>868</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>869</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>870</span> 
<span class='line'>871</span> </span><span class="COMM">/**
<span class='line'>872</span>  * convert IPv4/v6 addresss to a hexadecimal string&lt;br/>
<span class='line'>873</span>  * @name iptohex
<span class='line'>874</span>  * @function
<span class='line'>875</span>  * @param {String} s IPv4/v6 address string
<span class='line'>876</span>  * @return {String} hexadecimal string of IP address
<span class='line'>877</span>  * @since jsrsasign 8.0.12 base64x 1.1.14
<span class='line'>878</span>  * @description
<span class='line'>879</span>  * This function converts IPv4 or IPv6 address string to
<span class='line'>880</span>  * a hexadecimal string of IPv4 or IPv6 address.
<span class='line'>881</span>  * @example
<span class='line'>882</span>  * iptohex("192.168.1.1") &rarr "c0a80101"
<span class='line'>883</span>  * iptohex("2001:db8::4") &rarr "871020010db8000000000000000000000004"
<span class='line'>884</span>  * iptohex("zzz")) &rarr raise exception
<span class='line'>885</span>  */</span><span class="WHIT">
<span class='line'>886</span> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">iptohex</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>887</span> </span><span class="WHIT">  </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">malformedMsg</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">"malformed IP address"</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>888</span> </span><span class="WHIT">  </span><span class="NAME">s</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">s.toLowerCase</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>889</span> 
<span class='line'>890</span> </span><span class="WHIT">  </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">s.match</span><span class="PUNC">(</span><span class="REGX">/^[0-9.]+$/</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>891</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">a</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">s.split</span><span class="PUNC">(</span><span class="STRN">"."</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>892</span> </span><span class="WHIT">    </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">a.length</span><span class="WHIT"> </span><span class="PUNC">!==</span><span class="WHIT"> </span><span class="NUMB">4</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="KEYW">throw</span><span class="WHIT"> </span><span class="NAME">malformedMsg</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>893</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">hex</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">""</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>894</span> </span><span class="WHIT">    </span><span class="KEYW">try</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>895</span> </span><span class="WHIT">      </span><span class="KEYW">for</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NUMB">4</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="PUNC">++</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>896</span> </span><span class="WHIT">        </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">d</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">parseInt</span><span class="PUNC">(</span><span class="NAME">a</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>897</span> </span><span class="WHIT">        </span><span class="NAME">hex</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="STRN">"0"</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">d.toString</span><span class="PUNC">(</span><span class="NUMB">16</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">slice</span><span class="PUNC">(</span><span class="PUNC">-</span><span class="NUMB">2</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>898</span> </span><span class="WHIT">      </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>899</span> </span><span class="WHIT">      </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">hex</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>900</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT"> </span><span class="KEYW">catch</span><span class="PUNC">(</span><span class="NAME">ex</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>901</span> </span><span class="WHIT">      </span><span class="KEYW">throw</span><span class="WHIT"> </span><span class="NAME">malformedMsg</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>902</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>903</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="WHIT"> </span><span class="KEYW">else</span><span class="WHIT"> </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">s.match</span><span class="PUNC">(</span><span class="REGX">/^[0-9a-f:]+$/</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT"> </span><span class="NAME">s.indexOf</span><span class="PUNC">(</span><span class="STRN">":"</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">!==</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="NUMB">1</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>904</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">ipv6tohex</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>905</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="WHIT"> </span><span class="KEYW">else</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>906</span> </span><span class="WHIT">    </span><span class="KEYW">throw</span><span class="WHIT"> </span><span class="NAME">malformedMsg</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>907</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>908</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>909</span> 
<span class='line'>910</span> </span><span class="COMM">// ==== URIComponent ================================</span><span class="WHIT">
<span class='line'>911</span> </span><span class="COMM">/**
<span class='line'>912</span>  * convert UTFa hexadecimal string to a URLComponent string such like "%67%68".&lt;br/>
<span class='line'>913</span>  * Note that these "&lt;code>0-9A-Za-z!'()*-._~&lt;/code>" characters will not
<span class='line'>914</span>  * converted to "%xx" format by builtin 'encodeURIComponent()' function.
<span class='line'>915</span>  * However this 'encodeURIComponentAll()' function will convert 
<span class='line'>916</span>  * all of characters into "%xx" format.
<span class='line'>917</span>  * @name encodeURIComponentAll
<span class='line'>918</span>  * @function
<span class='line'>919</span>  * @param {String} s hexadecimal string
<span class='line'>920</span>  * @return {String} URIComponent string such like "%67%68"
<span class='line'>921</span>  * @since 1.1
<span class='line'>922</span>  */</span><span class="WHIT">
<span class='line'>923</span> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">encodeURIComponentAll</span><span class="PUNC">(</span><span class="NAME">u8</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>924</span> </span><span class="WHIT">  </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">s</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">encodeURIComponent</span><span class="PUNC">(</span><span class="NAME">u8</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>925</span> </span><span class="WHIT">  </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">s2</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">""</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>926</span> </span><span class="WHIT">  </span><span class="KEYW">for</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NAME">s.length</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="PUNC">++</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>927</span> </span><span class="WHIT">    </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="STRN">"%"</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>928</span> </span><span class="WHIT">      </span><span class="NAME">s2</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">s2</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">s.substr</span><span class="PUNC">(</span><span class="NAME">i</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">3</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>929</span> </span><span class="WHIT">      </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>930</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT"> </span><span class="KEYW">else</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>931</span> </span><span class="WHIT">      </span><span class="NAME">s2</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">s2</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="STRN">"%"</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">stohex</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>932</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>933</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>934</span> </span><span class="WHIT">  </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">s2</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>935</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>936</span> 
<span class='line'>937</span> </span><span class="COMM">// ==== new lines ================================</span><span class="WHIT">
<span class='line'>938</span> </span><span class="COMM">/**
<span class='line'>939</span>  * convert all DOS new line("\r\n") to UNIX new line("\n") in 
<span class='line'>940</span>  * a String "s".
<span class='line'>941</span>  * @name newline_toUnix
<span class='line'>942</span>  * @function
<span class='line'>943</span>  * @param {String} s string 
<span class='line'>944</span>  * @return {String} converted string
<span class='line'>945</span>  */</span><span class="WHIT">
<span class='line'>946</span> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">newline_toUnix</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>947</span> </span><span class="WHIT">    </span><span class="NAME">s</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">s.replace</span><span class="PUNC">(</span><span class="REGX">/\r\n/mg</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"\n"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>948</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">s</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>949</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>950</span> 
<span class='line'>951</span> </span><span class="COMM">/**
<span class='line'>952</span>  * convert all UNIX new line("\r\n") to DOS new line("\n") in 
<span class='line'>953</span>  * a String "s".
<span class='line'>954</span>  * @name newline_toDos
<span class='line'>955</span>  * @function
<span class='line'>956</span>  * @param {String} s string 
<span class='line'>957</span>  * @return {String} converted string
<span class='line'>958</span>  */</span><span class="WHIT">
<span class='line'>959</span> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">newline_toDos</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>960</span> </span><span class="WHIT">    </span><span class="NAME">s</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">s.replace</span><span class="PUNC">(</span><span class="REGX">/\r\n/mg</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"\n"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>961</span> </span><span class="WHIT">    </span><span class="NAME">s</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">s.replace</span><span class="PUNC">(</span><span class="REGX">/\n/mg</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"\r\n"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>962</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">s</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>963</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>964</span> 
<span class='line'>965</span> </span><span class="COMM">// ==== string type checker ===================</span><span class="WHIT">
<span class='line'>966</span> 
<span class='line'>967</span> </span><span class="COMM">/**
<span class='line'>968</span>  * check whether a string is an integer string or not&lt;br/>
<span class='line'>969</span>  * @name isInteger
<span class='line'>970</span>  * @memberOf KJUR.lang.String
<span class='line'>971</span>  * @function
<span class='line'>972</span>  * @static
<span class='line'>973</span>  * @param {String} s input string
<span class='line'>974</span>  * @return {Boolean} true if a string "s" is an integer string otherwise false
<span class='line'>975</span>  * @since base64x 1.1.7 jsrsasign 5.0.13
<span class='line'>976</span>  * @example
<span class='line'>977</span>  * KJUR.lang.String.isInteger("12345") &rarr; true
<span class='line'>978</span>  * KJUR.lang.String.isInteger("123ab") &rarr; false
<span class='line'>979</span>  */</span><span class="WHIT">
<span class='line'>980</span> </span><span class="NAME">KJUR.lang.String.isInteger</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>981</span> </span><span class="WHIT">    </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">s.match</span><span class="PUNC">(</span><span class="REGX">/^[0-9]+$/</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>982</span> </span><span class="WHIT">	</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>983</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT"> </span><span class="KEYW">else</span><span class="WHIT"> </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">s.match</span><span class="PUNC">(</span><span class="REGX">/^-[0-9]+$/</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>984</span> </span><span class="WHIT">	</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>985</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT"> </span><span class="KEYW">else</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>986</span> </span><span class="WHIT">	</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>987</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>988</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>989</span> 
<span class='line'>990</span> </span><span class="COMM">/**
<span class='line'>991</span>  * check whether a string is an hexadecimal string or not&lt;br/>
<span class='line'>992</span>  * @name isHex
<span class='line'>993</span>  * @memberOf KJUR.lang.String
<span class='line'>994</span>  * @function
<span class='line'>995</span>  * @static
<span class='line'>996</span>  * @param {String} s input string
<span class='line'>997</span>  * @return {Boolean} true if a string "s" is an hexadecimal string otherwise false
<span class='line'>998</span>  * @since base64x 1.1.7 jsrsasign 5.0.13
<span class='line'>999</span>  * @example
<span class='line'>1000</span>  * KJUR.lang.String.isHex("1234") &rarr; true
<span class='line'>1001</span>  * KJUR.lang.String.isHex("12ab") &rarr; true
<span class='line'>1002</span>  * KJUR.lang.String.isHex("12AB") &rarr; true
<span class='line'>1003</span>  * KJUR.lang.String.isHex("12ZY") &rarr; false
<span class='line'>1004</span>  * KJUR.lang.String.isHex("121") &rarr; false -- odd length
<span class='line'>1005</span>  */</span><span class="WHIT">
<span class='line'>1006</span> </span><span class="NAME">KJUR.lang.String.isHex</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1007</span> </span><span class="WHIT">    </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">s.length</span><span class="WHIT"> </span><span class="PUNC">%</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT">
<span class='line'>1008</span> </span><span class="WHIT">	</span><span class="PUNC">(</span><span class="NAME">s.match</span><span class="PUNC">(</span><span class="REGX">/^[0-9a-f]+$/</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NAME">s.match</span><span class="PUNC">(</span><span class="REGX">/^[0-9A-F]+$/</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1009</span> </span><span class="WHIT">	</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1010</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT"> </span><span class="KEYW">else</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1011</span> </span><span class="WHIT">	</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1012</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>1013</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1014</span> 
<span class='line'>1015</span> </span><span class="COMM">/**
<span class='line'>1016</span>  * check whether a string is a base64 encoded string or not&lt;br/>
<span class='line'>1017</span>  * Input string can conclude new lines or space characters.
<span class='line'>1018</span>  * @name isBase64
<span class='line'>1019</span>  * @memberOf KJUR.lang.String
<span class='line'>1020</span>  * @function
<span class='line'>1021</span>  * @static
<span class='line'>1022</span>  * @param {String} s input string
<span class='line'>1023</span>  * @return {Boolean} true if a string "s" is a base64 encoded string otherwise false
<span class='line'>1024</span>  * @since base64x 1.1.7 jsrsasign 5.0.13
<span class='line'>1025</span>  * @example
<span class='line'>1026</span>  * KJUR.lang.String.isBase64("YWE=") &rarr; true
<span class='line'>1027</span>  * KJUR.lang.String.isBase64("YW_=") &rarr; false
<span class='line'>1028</span>  * KJUR.lang.String.isBase64("YWE") &rarr; false -- length shall be multiples of 4
<span class='line'>1029</span>  */</span><span class="WHIT">
<span class='line'>1030</span> </span><span class="NAME">KJUR.lang.String.isBase64</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1031</span> </span><span class="WHIT">    </span><span class="NAME">s</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">s.replace</span><span class="PUNC">(</span><span class="REGX">/\s+/g</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">""</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1032</span> </span><span class="WHIT">    </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">s.match</span><span class="PUNC">(</span><span class="REGX">/^[0-9A-Za-z+\/]+={0,3}$/</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT"> </span><span class="NAME">s.length</span><span class="WHIT"> </span><span class="PUNC">%</span><span class="WHIT"> </span><span class="NUMB">4</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1033</span> </span><span class="WHIT">	</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1034</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT"> </span><span class="KEYW">else</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1035</span> </span><span class="WHIT">	</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1036</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>1037</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1038</span> 
<span class='line'>1039</span> </span><span class="COMM">/**
<span class='line'>1040</span>  * check whether a string is a base64url encoded string or not&lt;br/>
<span class='line'>1041</span>  * Input string can conclude new lines or space characters.
<span class='line'>1042</span>  * @name isBase64URL
<span class='line'>1043</span>  * @memberOf KJUR.lang.String
<span class='line'>1044</span>  * @function
<span class='line'>1045</span>  * @static
<span class='line'>1046</span>  * @param {String} s input string
<span class='line'>1047</span>  * @return {Boolean} true if a string "s" is a base64url encoded string otherwise false
<span class='line'>1048</span>  * @since base64x 1.1.7 jsrsasign 5.0.13
<span class='line'>1049</span>  * @example
<span class='line'>1050</span>  * KJUR.lang.String.isBase64URL("YWE") &rarr; true
<span class='line'>1051</span>  * KJUR.lang.String.isBase64URL("YW-") &rarr; true
<span class='line'>1052</span>  * KJUR.lang.String.isBase64URL("YW+") &rarr; false
<span class='line'>1053</span>  */</span><span class="WHIT">
<span class='line'>1054</span> </span><span class="NAME">KJUR.lang.String.isBase64URL</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1055</span> </span><span class="WHIT">    </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">s.match</span><span class="PUNC">(</span><span class="REGX">/[+/</span><span class="PUNC">=</span><span class="PUNC">]</span><span class="PUNC">/</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1056</span> </span><span class="WHIT">    </span><span class="NAME">s</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">b64utob64</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1057</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">KJUR.lang.String.isBase64</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1058</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1059</span> 
<span class='line'>1060</span> </span><span class="COMM">/**
<span class='line'>1061</span>  * check whether a string is a string of integer array or not&lt;br/>
<span class='line'>1062</span>  * Input string can conclude new lines or space characters.
<span class='line'>1063</span>  * @name isIntegerArray
<span class='line'>1064</span>  * @memberOf KJUR.lang.String
<span class='line'>1065</span>  * @function
<span class='line'>1066</span>  * @static
<span class='line'>1067</span>  * @param {String} s input string
<span class='line'>1068</span>  * @return {Boolean} true if a string "s" is a string of integer array otherwise false
<span class='line'>1069</span>  * @since base64x 1.1.7 jsrsasign 5.0.13
<span class='line'>1070</span>  * @example
<span class='line'>1071</span>  * KJUR.lang.String.isIntegerArray("[1,2,3]") &rarr; true
<span class='line'>1072</span>  * KJUR.lang.String.isIntegerArray("  [1, 2, 3  ] ") &rarr; true
<span class='line'>1073</span>  * KJUR.lang.String.isIntegerArray("[a,2]") &rarr; false
<span class='line'>1074</span>  */</span><span class="WHIT">
<span class='line'>1075</span> </span><span class="NAME">KJUR.lang.String.isIntegerArray</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1076</span> </span><span class="WHIT">    </span><span class="NAME">s</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">s.replace</span><span class="PUNC">(</span><span class="REGX">/\s+/g</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">""</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1077</span> </span><span class="WHIT">    </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">s.match</span><span class="PUNC">(</span><span class="REGX">/^\[[0-9,]+\]$/</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1078</span> </span><span class="WHIT">	</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1079</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT"> </span><span class="KEYW">else</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1080</span> </span><span class="WHIT">	</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1081</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>1082</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1083</span> 
<span class='line'>1084</span> </span><span class="COMM">// ==== others ================================</span><span class="WHIT">
<span class='line'>1085</span> 
<span class='line'>1086</span> </span><span class="COMM">/**
<span class='line'>1087</span>  * canonicalize hexadecimal string of positive integer&lt;br/>
<span class='line'>1088</span>  * @name hextoposhex
<span class='line'>1089</span>  * @function
<span class='line'>1090</span>  * @param {String} s hexadecimal string 
<span class='line'>1091</span>  * @return {String} canonicalized hexadecimal string of positive integer
<span class='line'>1092</span>  * @since base64x 1.1.10 jsrsasign 7.1.4
<span class='line'>1093</span>  * @description
<span class='line'>1094</span>  * This method canonicalize a hexadecimal string of positive integer
<span class='line'>1095</span>  * for two's complement representation.
<span class='line'>1096</span>  * Canonicalized hexadecimal string of positive integer will be:
<span class='line'>1097</span>  * &lt;ul>
<span class='line'>1098</span>  * &lt;li>Its length is always even.&lt;/li>
<span class='line'>1099</span>  * &lt;li>If odd length it will be padded with leading zero.&lt;li>
<span class='line'>1100</span>  * &lt;li>If it is even length and its first character is "8" or greater,
<span class='line'>1101</span>  * it will be padded with "00" to make it positive integer.&lt;/li>
<span class='line'>1102</span>  * &lt;/ul>
<span class='line'>1103</span>  * @example
<span class='line'>1104</span>  * hextoposhex("abcd") &rarr; "00abcd"
<span class='line'>1105</span>  * hextoposhex("1234") &rarr; "1234"
<span class='line'>1106</span>  * hextoposhex("12345") &rarr; "012345"
<span class='line'>1107</span>  */</span><span class="WHIT">
<span class='line'>1108</span> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">hextoposhex</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1109</span> </span><span class="WHIT">    </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">s.length</span><span class="WHIT"> </span><span class="PUNC">%</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="NUMB">1</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="STRN">"0"</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">s</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1110</span> </span><span class="WHIT">    </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">s.substr</span><span class="PUNC">(</span><span class="NUMB">0</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">1</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">></span><span class="WHIT"> </span><span class="STRN">"7"</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="STRN">"00"</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">s</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1111</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">s</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1112</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>1113</span> 
<span class='line'>1114</span> </span><span class="COMM">/**
<span class='line'>1115</span>  * convert string of integer array to hexadecimal string.&lt;br/>
<span class='line'>1116</span>  * @name intarystrtohex
<span class='line'>1117</span>  * @function
<span class='line'>1118</span>  * @param {String} s string of integer array
<span class='line'>1119</span>  * @return {String} hexadecimal string
<span class='line'>1120</span>  * @since base64x 1.1.6 jsrsasign 5.0.2
<span class='line'>1121</span>  * @throws "malformed integer array string: *" for wrong input
<span class='line'>1122</span>  * @description
<span class='line'>1123</span>  * This function converts a string of JavaScript integer array to
<span class='line'>1124</span>  * a hexadecimal string. Each integer value shall be in a range 
<span class='line'>1125</span>  * from 0 to 255 otherwise it raise exception. Input string can
<span class='line'>1126</span>  * have extra space or newline string so that they will be ignored.
<span class='line'>1127</span>  * 
<span class='line'>1128</span>  * @example
<span class='line'>1129</span>  * intarystrtohex(" [123, 34, 101, 34, 58] ")
<span class='line'>1130</span>  * &rarr; 7b2265223a (i.e. '{"e":' as string)
<span class='line'>1131</span>  */</span><span class="WHIT">
<span class='line'>1132</span> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">intarystrtohex</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1133</span> </span><span class="WHIT">  </span><span class="NAME">s</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">s.replace</span><span class="PUNC">(</span><span class="REGX">/^\s*\[\s*/</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">''</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1134</span> </span><span class="WHIT">  </span><span class="NAME">s</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">s.replace</span><span class="PUNC">(</span><span class="REGX">/\s*\]\s*$/</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">''</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1135</span> </span><span class="WHIT">  </span><span class="NAME">s</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">s.replace</span><span class="PUNC">(</span><span class="REGX">/\s*/g</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">''</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1136</span> </span><span class="WHIT">  </span><span class="KEYW">try</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1137</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">hex</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">s.split</span><span class="PUNC">(</span><span class="REGX">/,/</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">map</span><span class="PUNC">(</span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">element</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">index</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">array</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1138</span> </span><span class="WHIT">      </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">parseInt</span><span class="PUNC">(</span><span class="NAME">element</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1139</span> </span><span class="WHIT">      </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NUMB">255</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="KEYW">throw</span><span class="WHIT"> </span><span class="STRN">"integer not in range 0-255"</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1140</span> </span><span class="WHIT">      </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">hI</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="STRN">"00"</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">i.toString</span><span class="PUNC">(</span><span class="NUMB">16</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">slice</span><span class="PUNC">(</span><span class="PUNC">-</span><span class="NUMB">2</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1141</span> </span><span class="WHIT">      </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">hI</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1142</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">join</span><span class="PUNC">(</span><span class="STRN">''</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1143</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">hex</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1144</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="WHIT"> </span><span class="KEYW">catch</span><span class="PUNC">(</span><span class="NAME">ex</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1145</span> </span><span class="WHIT">    </span><span class="KEYW">throw</span><span class="WHIT"> </span><span class="STRN">"malformed integer array string: "</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">ex</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1146</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>1147</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>1148</span> 
<span class='line'>1149</span> </span><span class="COMM">/**
<span class='line'>1150</span>  * find index of string where two string differs
<span class='line'>1151</span>  * @name strdiffidx
<span class='line'>1152</span>  * @function
<span class='line'>1153</span>  * @param {String} s1 string to compare
<span class='line'>1154</span>  * @param {String} s2 string to compare
<span class='line'>1155</span>  * @return {Number} string index of where character differs. Return -1 if same.
<span class='line'>1156</span>  * @since jsrsasign 4.9.0 base64x 1.1.5
<span class='line'>1157</span>  * @example
<span class='line'>1158</span>  * strdiffidx("abcdefg", "abcd4fg") -> 4
<span class='line'>1159</span>  * strdiffidx("abcdefg", "abcdefg") -> -1
<span class='line'>1160</span>  * strdiffidx("abcdefg", "abcdef") -> 6
<span class='line'>1161</span>  * strdiffidx("abcdefgh", "abcdef") -> 6
<span class='line'>1162</span>  */</span><span class="WHIT">
<span class='line'>1163</span> </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">strdiffidx</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">s1</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">s2</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1164</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">n</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">s1.length</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1165</span> </span><span class="WHIT">    </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">s1.length</span><span class="WHIT"> </span><span class="PUNC">></span><span class="WHIT"> </span><span class="NAME">s2.length</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="NAME">n</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">s2.length</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1166</span> </span><span class="WHIT">    </span><span class="KEYW">for</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NAME">n</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="PUNC">++</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1167</span> </span><span class="WHIT">	</span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">s1.charCodeAt</span><span class="PUNC">(</span><span class="NAME">i</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">!=</span><span class="WHIT"> </span><span class="NAME">s2.charCodeAt</span><span class="PUNC">(</span><span class="NAME">i</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">i</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1168</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>1169</span> </span><span class="WHIT">    </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">s1.length</span><span class="WHIT"> </span><span class="PUNC">!=</span><span class="WHIT"> </span><span class="NAME">s2.length</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">n</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1170</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="NUMB">1</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="COMM">// same</span><span class="WHIT">
<span class='line'>1171</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1172</span> 
<span class='line'>1173</span> 
<span class='line'>1174</span> </span></pre></body></html>